//
//  QZTableViewCell.m
//  QZSelectedTableViewCell
//
//  Created by 000 on 16/11/22.
//  Copyright © 2016年 faner. All rights reserved.
//

#import "QZTableViewCell.h"

@implementation QZTableViewCell

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
}

- (void)setCheckImageViewCenter:(CGPoint)pt alpha:(CGFloat)alpha animated:(BOOL)animated{
    if (animated){
        [UIView animateWithDuration:0.3 animations:^{
            _checkImageView.center = pt;
            _checkImageView.alpha = alpha;
        } completion:^(BOOL finished) {
            [self setChecked:NO];
        }];
        return;
    }
    _checkImageView.center = pt;
    _checkImageView.alpha = alpha;
    
}

- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
    [super setEditing:editing animated:animated];
    if (editing) {
        if (_checkImageView == nil) {
            _checkImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"unchecked.png"]];
            _checkImageView.bounds = CGRectMake(0, 0, 20, 20);
            [self addSubview:_checkImageView];
        }
        [self setChecked:_checked];
        _checkImageView.center = CGPointMake(-CGRectGetWidth(_checkImageView.frame) * 0.5 ,
                                             CGRectGetHeight(self.bounds) * 0.5);

        return;

    }
    _checked = NO;
    if (_checkImageView){
        [self setCheckImageViewCenter:CGPointMake(-CGRectGetWidth(_checkImageView.frame) * 0.5 ,
                                                  CGRectGetHeight(self.bounds) * 0.5)
                                alpha:0.0
                             animated:animated];
    }

}

- (void)setChecked:(BOOL)checked
{
    _checked = checked;
    
}

@end
